#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<unistd.h>

FILE *fp,*fp1;
char buffer[1024];
pid_t pid;
#define pripipe "private"
#define pubpipe "public"
int main()
{
	if((fp=fopen(pubpipe,"w"))==NULL)
	{
		printf("open fp failed.\n");
		exit(1);
	}
	
	sprintf(buffer,"用户%d进入聊天室", getpid());
	if(fputs(buffer,fp)==EOF)
	{
		printf("fputs error!\n");
		exit(1);
	}
	fclose(fp);

	while(1){
		if((fp=fopen(pubpipe,"w"))==NULL)
		{
			printf("open fp failed.\n");
			exit(1);
		}
		
		printf("请输入：");
		scanf("%s",buffer);
		if(fputs(buffer,fp)==EOF)
		{
			printf("fputs error!\n");
			exit(1);
		}
		fclose(fp);
		usleep(100000);
		if(strcmp(buffer,"quit")==0)
			exit(1);	
	}
    return 0;
}
